﻿using LCL.CodeHelper;
using LCL.IBuilder;
using LCL.LData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace LCL.Builder.SimpleFactory
{
    public partial class ProjectBuilder
    {
        #region BuilderDAL
        private void BuilderDAL()
        {
            var tables = DbObject.GetTables(DbName);
            foreach (var table in tables)
            {
                #region MyRegion
                var Fieldlist = DbObject.GetColumnInfoList(DbName, table.TableName);
                List<TableColumn> Keys = Fieldlist.Where(p => p.IsPrimaryKey == true).ToList();
                string className = CodeCommon.GetClassName(table.TableName, TableFormat);
                string ModelSpace = NameSpace + ".Model." + className;//命名空间 + 类名
                string DALSpace = NameSpace + ".DAL." + className;
                string BLLSpace = NameSpace + ".BLL." + className;

                StringBuilder builder = new StringBuilder();
                builder.AppendLine("using System;  ");
                builder.AppendLine("using System.Text; ");
                builder.AppendLine("using System.Collections.Generic;  ");
                builder.AppendLine("using System.Data; ");
                builder.AppendLine("using LCL;  ");
                builder.AppendLine("using LCL.LData; ");
                builder.AppendLine("using LCL.Config;  ");
                builder.AppendLine("using " + NameSpace + ".IDAL; ");
                builder.AppendLine("namespace " + NameSpace + ".DAL   ");
                builder.AppendLine("{ ");
                builder.AppendLine("  /// <summary> ");
                builder.AppendLine("  /// " + table.TableName + table.TableNameRemark);
                builder.AppendLine(" /// </summary> ");
                builder.AppendLine("    public partial class " + className + ":I" + className + "DAL ");
                builder.AppendLine("	{ ");
                builder.AppendLine("	    DbAccesser idb = DBOMaker.GetDbAccesser(DbConfig.GetConfig()); ");
                builder.AppendLine("		public bool Exists(" + CodeCommon.GetInParameter(Keys) + ") ");
                builder.AppendLine("		{ ");
                builder.AppendLine("		    int ret = 0; ");
                builder.AppendLine("			StringBuilder strSql=new StringBuilder(); ");
                builder.AppendLine("			strSql.Append(\"select count(1) from " + table.TableName + "\"); ");
                builder.AppendLine("			strSql.Append(\" where \"); ");
                builder.AppendLine("			strSql.Append(\" " + CodeCommon.GetWhereExpression(Keys) + " \"); ");
                builder.AppendLine("			var retun = idb.ExecuteScalar(strSql.ToString()); ");
                builder.AppendLine("            if (retun != null) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                ret = int.Parse(retun.ToString()); ");
                builder.AppendLine("            } ");
                builder.AppendLine("            return ret > 0; ");
                builder.AppendLine("		} ");
                builder.AppendLine("		/// <summary> ");
                builder.AppendLine("		/// 增加一条数据 ");
                builder.AppendLine("		/// </summary> ");
                builder.AppendLine("		public int Add(" + ModelSpace + " model) ");
                builder.AppendLine("		{ ");
                builder.AppendLine("		    StringBuilder strSql = new StringBuilder(); ");
                builder.AppendLine("            StringBuilder strSql1 = new StringBuilder(); ");
                builder.AppendLine("            StringBuilder strSql2 = new StringBuilder(); ");
                foreach (var field in Fieldlist)
                {
                    string columnName = field.ColumnName;
                    string columnType = field.ColumnType;
                    bool IsIdentity = field.IsIdentity;
                    if (IsIdentity)
                    {
                        continue;
                    }
                    builder.AppendLine("		if (model." + columnName + " != null) ");
                    builder.AppendLine("		{ ");
                    builder.AppendLine("			strSql1.Append(\"" + columnName + ",\"); ");
                    if ((DbType == LDbType.Oracle) && (columnType.ToLower() == "date" || columnType.ToLower() == "datetime"))
                    {
                        builder.AppendLine("strSql2.Append(\"to_date('\" + model." + columnName + ".ToString() + \"','YYYY-MM-DD HH24:MI:SS'),\");");
                    }
                    else
                    {
                        if (columnType.ToLower() == "bit")
                        {
                            builder.AppendLine("strSql2.Append(\"\"+(model." + columnName + "? 1 : 0) +\",\");");
                        }
                        else
                        {
                            if (CodeCommon.IsAddMark(columnType.Trim()))
                            {
                                builder.AppendLine("strSql2.Append(\"'\"+model." + columnName + "+\"',\");");
                            }
                            else
                            {
                                builder.AppendLine("strSql2.Append(\"\"+model." + columnName + "+\",\");");
                            }
                        }
                    }

                    builder.AppendLine("		} ");
                }
                builder.AppendLine("		    strSql.Append(\"insert into " + table.TableName + "(\"); ");
                builder.AppendLine("            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); ");
                builder.AppendLine("            strSql.Append(\")\"); ");
                builder.AppendLine("            strSql.Append(\" values (\"); ");
                builder.AppendLine("            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); ");
                builder.AppendLine("            strSql.Append(\")\"); ");
                builder.AppendLine("            object obj =idb.ExecuteNonQuery(strSql.ToString()); ");
                builder.AppendLine("            if (obj == null) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return 0; ");
                builder.AppendLine("            } ");
                builder.AppendLine("            else ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return Convert.ToInt32(obj); ");
                builder.AppendLine("            } ");
                builder.AppendLine("		} ");
                builder.AppendLine(" ");
                builder.AppendLine("		/// <summary> ");
                builder.AppendLine("		/// 更新一条数据 ");
                builder.AppendLine("		/// </summary> ");
                builder.AppendLine("		public bool Update(" + ModelSpace + " model) ");
                builder.AppendLine("		{ ");
                builder.AppendLine("		   StringBuilder strSql = new StringBuilder(); ");
                builder.AppendLine("           strSql.Append(\"update " + table.TableName + " set \"); ");
                foreach (var field in Fieldlist)
                {
                    string columnName = field.ColumnName;
                    string columnType = field.ColumnType;
                    bool IsIdentity = field.IsIdentity;
                    if (IsIdentity)
                    {
                        continue;
                    }
                    builder.AppendLine("		if (model." + columnName + " != null) ");
                    builder.AppendLine("		{ ");
                    builder.AppendLine("		 strSql.Append(\"" + columnName + "='\" + model." + columnName + " + \"',\"); ");
                    builder.AppendLine("		} ");
                }
                builder.AppendLine("             ");
                builder.AppendLine("			int n = strSql.ToString().LastIndexOf(\",\"); ");
                builder.AppendLine("            strSql.Remove(n, 1); ");
                builder.AppendLine(" ");
                builder.AppendLine("		    strSql.Append(\" where " + CodeCommon.GetModelWhereExpression(Keys) + "  \"); ");
                builder.AppendLine(" ");
                builder.AppendLine("            int rows = idb.ExecuteNonQuery(strSql.ToString()); ");
                builder.AppendLine("            if (rows > 0) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return true; ");
                builder.AppendLine("            } ");
                builder.AppendLine("            else ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return false; ");
                builder.AppendLine("            } ");
                builder.AppendLine("		} ");
                builder.AppendLine("		/// <summary> ");
                builder.AppendLine("		/// 删除一条数据 ");
                builder.AppendLine("		/// </summary> ");
                builder.AppendLine("		public bool Delete(" + CodeCommon.GetInParameter(Keys) + ") ");
                builder.AppendLine("		{ ");
                builder.AppendLine("			StringBuilder strSql = new StringBuilder(); ");
                builder.AppendLine("            strSql.Append(\"delete from " + table.TableName + " \"); ");
                builder.AppendLine("            strSql.Append(\" where " + CodeCommon.GetWhereExpression(Keys) + "\"); ");
                builder.AppendLine("            int rowsAffected = idb.ExecuteNonQuery(strSql.ToString()); ");
                builder.AppendLine("            if (rowsAffected > 0) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return true; ");
                builder.AppendLine("            } ");
                builder.AppendLine("            else ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return false; ");
                builder.AppendLine("            } ");
                builder.AppendLine("		} ");
                builder.AppendLine("		/// <summary> ");
                builder.AppendLine("		/// 得到一个对象实体 ");
                builder.AppendLine("		/// </summary> ");
                builder.AppendLine("		public " + ModelSpace + " GetModel(" + CodeCommon.GetInParameter(Keys) + ") ");
                builder.AppendLine("		{ ");
                builder.AppendLine("		    StringBuilder strSql = new StringBuilder(); ");
                builder.AppendLine("            strSql.Append(\"select  \"); ");
                builder.AppendLine("            strSql.Append(\" * \"); ");
                builder.AppendLine("            strSql.Append(\" from " + table.TableName + " \"); ");
                builder.AppendLine("            strSql.Append(\" where " + CodeCommon.GetWhereExpression(Keys) + " \"); ");
                builder.AppendLine("            " + ModelSpace + " model = new " + ModelSpace + "(); ");
                builder.AppendLine("            DataTable ds =idb.ExecuteDataTable(strSql.ToString()); ");
                builder.AppendLine("            if (ds.Rows.Count > 0) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return DataRowToModel(ds.Rows[0]); ");
                builder.AppendLine("            } ");
                builder.AppendLine("            else ");
                builder.AppendLine("            { ");
                builder.AppendLine("                return null; ");
                builder.AppendLine("            } ");
                builder.AppendLine("		} ");
                builder.AppendLine("		 ");
                builder.AppendLine("		/// <summary> ");
                builder.AppendLine("		/// 获得数据列表 ");
                builder.AppendLine("		/// </summary> ");
                builder.AppendLine("		public DataTable GetList(string strWhere) ");
                builder.AppendLine("		{ ");
                builder.AppendLine("			StringBuilder strSql=new StringBuilder(); ");
                builder.AppendLine("			strSql.Append(\"select * \"); ");
                builder.AppendLine("			strSql.Append(\" from " + table.TableName + " \"); ");
                builder.AppendLine("			if(strWhere.Trim()!=\"\") ");
                builder.AppendLine("			{ ");
                builder.AppendLine("				strSql.Append(\" where \"+strWhere); ");
                builder.AppendLine("			} ");
                builder.AppendLine("			return idb.ExecuteDataTable(strSql.ToString()); ");
                builder.AppendLine("		} ");
                builder.AppendLine("		 /// <summary> ");
                builder.AppendLine("        /// 获得数据列表 ");
                builder.AppendLine("        /// </summary> ");
                builder.AppendLine("        public List<" + ModelSpace + "> GetListModel(string strWhere) ");
                builder.AppendLine("        { ");
                builder.AppendLine("            List<" + ModelSpace + "> list = new List<" + ModelSpace + ">(); ");
                builder.AppendLine("            StringBuilder strSql = new StringBuilder(); ");
                builder.AppendLine("            strSql.Append(\"select * \"); ");
                builder.AppendLine("            strSql.Append(\" from " + table.TableName + " \"); ");
                builder.AppendLine("            if (strWhere.Trim() != \"\") ");
                builder.AppendLine("            { ");
                builder.AppendLine("                strSql.Append(\" where \" + strWhere); ");
                builder.AppendLine("            } ");
                builder.AppendLine("            var table = idb.ExecuteDataTable(strSql.ToString()); ");
                builder.AppendLine("            foreach (DataRow row in table.Rows) ");
                builder.AppendLine("            { ");
                builder.AppendLine("                var entity = DataRowToModel(row); ");
                builder.AppendLine("                list.Add(entity); ");
                builder.AppendLine("            } ");
                builder.AppendLine("            return list; ");
                builder.AppendLine("        } ");
                builder.AppendLine("		 /// <summary> ");
                builder.AppendLine("        /// 得到一个对象实体 ");
                builder.AppendLine("        /// </summary> ");
                builder.AppendLine("        public " + ModelSpace + " DataRowToModel(DataRow row) ");
                builder.AppendLine("        { ");
                builder.AppendLine("            " + ModelSpace + " model = new " + ModelSpace + "(); ");
                builder.AppendLine("            if (row != null) ");
                builder.AppendLine("            { ");
                foreach (var field in Fieldlist)
                {
                    string columnName = field.ColumnName;
                    string columnType = field.ColumnType;
                    bool IsIdentity = field.IsIdentity;
                    bool ispk = field.IsPrimaryKey;
                    bool cisnull = field.IsNullable;
                    string deText = field.ColumnRemark;
                    columnType = CodeCommon.DbTypeToCS(columnType);


                    builder.AppendLine("if (row[\"" + columnName + "\"] != null ) ");

                    builder.AppendLine("{ ");
                    builder.AppendLine(" model." + columnName + " =Utils.GetObjTranNull<" + columnType + ">(row[\"" + columnName + "\"]); ");
                    builder.AppendLine("} ");
                }
                builder.AppendLine("             } ");
                builder.AppendLine("            return model; ");
                builder.AppendLine("        } ");
                builder.AppendLine("	} ");
                builder.AppendLine("} ");

                string filename = CodeCommon.DesktopDirectory + NameSpace + @"/DAL/" + className + ".cs";
                CodeCommon.CreateFiles(filename, builder.ToString());
                #endregion
            }
            DALCsproj();
        }
        private void DALCsproj()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?> ");
            builder.AppendLine("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" ToolsVersion=\"4.0\"> ");
            builder.AppendLine("  <PropertyGroup> ");
            builder.AppendLine("    <ProjectType>Local</ProjectType> ");
            builder.AppendLine("    <ProductVersion>8.0.50727</ProductVersion> ");
            builder.AppendLine("    <SchemaVersion>2.0</SchemaVersion> ");
            builder.AppendLine("    <ProjectGuid>{" + DALGuid + "}</ProjectGuid> ");
            builder.AppendLine("    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration> ");
            builder.AppendLine("    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform> ");
            builder.AppendLine("    <ApplicationIcon> ");
            builder.AppendLine("    </ApplicationIcon> ");
            builder.AppendLine("    <AssemblyKeyContainerName> ");
            builder.AppendLine("    </AssemblyKeyContainerName> ");
            builder.AppendLine("    <AssemblyName>" + NameSpace + ".DAL</AssemblyName> ");
            builder.AppendLine("    <AssemblyOriginatorKeyFile> ");
            builder.AppendLine("    </AssemblyOriginatorKeyFile> ");
            builder.AppendLine("    <DefaultClientScript>JScript</DefaultClientScript> ");
            builder.AppendLine("    <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> ");
            builder.AppendLine("    <DefaultTargetSchema>IE50</DefaultTargetSchema> ");
            builder.AppendLine("    <DelaySign>false</DelaySign> ");
            builder.AppendLine("    <OutputType>Library</OutputType> ");
            builder.AppendLine("    <RootNamespace>" + NameSpace + ".DAL</RootNamespace> ");
            builder.AppendLine("    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> ");
            builder.AppendLine("    <StartupObject> ");
            builder.AppendLine("    </StartupObject> ");
            builder.AppendLine("    <FileUpgradeFlags> ");
            builder.AppendLine("    </FileUpgradeFlags> ");
            builder.AppendLine("    <UpgradeBackupLocation> ");
            builder.AppendLine("    </UpgradeBackupLocation> ");
            builder.AppendLine("    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> ");
            builder.AppendLine("    <OldToolsVersion>2.0</OldToolsVersion> ");
            builder.AppendLine("    <PublishUrl>publish\\</PublishUrl> ");
            builder.AppendLine("    <Install>true</Install> ");
            builder.AppendLine("    <InstallFrom>Disk</InstallFrom> ");
            builder.AppendLine("    <UpdateEnabled>false</UpdateEnabled> ");
            builder.AppendLine("    <UpdateMode>Foreground</UpdateMode> ");
            builder.AppendLine("    <UpdateInterval>7</UpdateInterval> ");
            builder.AppendLine("    <UpdateIntervalUnits>Days</UpdateIntervalUnits> ");
            builder.AppendLine("    <UpdatePeriodically>false</UpdatePeriodically> ");
            builder.AppendLine("    <UpdateRequired>false</UpdateRequired> ");
            builder.AppendLine("    <MapFileExtensions>true</MapFileExtensions> ");
            builder.AppendLine("    <ApplicationRevision>0</ApplicationRevision> ");
            builder.AppendLine("    <ApplicationVersion>1.0.0.%2a</ApplicationVersion> ");
            builder.AppendLine("    <IsWebBootstrapper>false</IsWebBootstrapper> ");
            builder.AppendLine("    <UseApplicationTrust>false</UseApplicationTrust> ");
            builder.AppendLine("    <BootstrapperEnabled>true</BootstrapperEnabled> ");
            builder.AppendLine("    <TargetFrameworkProfile /> ");
            builder.AppendLine("  </PropertyGroup> ");
            builder.AppendLine("  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \"> ");
            builder.AppendLine("    <OutputPath>bin\\Debug\\</OutputPath> ");
            builder.AppendLine("    <AllowUnsafeBlocks>false</AllowUnsafeBlocks> ");
            builder.AppendLine("    <BaseAddress>285212672</BaseAddress> ");
            builder.AppendLine("    <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> ");
            builder.AppendLine("    <ConfigurationOverrideFile> ");
            builder.AppendLine("    </ConfigurationOverrideFile> ");
            builder.AppendLine("    <DefineConstants>DEBUG;TRACE</DefineConstants> ");
            builder.AppendLine("    <DocumentationFile> ");
            builder.AppendLine("    </DocumentationFile> ");
            builder.AppendLine("    <DebugSymbols>true</DebugSymbols> ");
            builder.AppendLine("    <FileAlignment>4096</FileAlignment> ");
            builder.AppendLine("    <NoStdLib>false</NoStdLib> ");
            builder.AppendLine("    <NoWarn> ");
            builder.AppendLine("    </NoWarn> ");
            builder.AppendLine("    <Optimize>false</Optimize> ");
            builder.AppendLine("    <RegisterForComInterop>false</RegisterForComInterop> ");
            builder.AppendLine("    <RemoveIntegerChecks>false</RemoveIntegerChecks> ");
            builder.AppendLine("    <TreatWarningsAsErrors>false</TreatWarningsAsErrors> ");
            builder.AppendLine("    <WarningLevel>4</WarningLevel> ");
            builder.AppendLine("    <DebugType>full</DebugType> ");
            builder.AppendLine("    <ErrorReport>prompt</ErrorReport> ");
            builder.AppendLine("    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> ");
            builder.AppendLine("  </PropertyGroup> ");
            builder.AppendLine("  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \"> ");
            builder.AppendLine("    <OutputPath>bin\\Release\\</OutputPath> ");
            builder.AppendLine("    <AllowUnsafeBlocks>false</AllowUnsafeBlocks> ");
            builder.AppendLine("    <BaseAddress>285212672</BaseAddress> ");
            builder.AppendLine("    <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> ");
            builder.AppendLine("    <ConfigurationOverrideFile> ");
            builder.AppendLine("    </ConfigurationOverrideFile> ");
            builder.AppendLine("    <DefineConstants>TRACE</DefineConstants> ");
            builder.AppendLine("    <DocumentationFile> ");
            builder.AppendLine("    </DocumentationFile> ");
            builder.AppendLine("    <DebugSymbols>false</DebugSymbols> ");
            builder.AppendLine("    <FileAlignment>4096</FileAlignment> ");
            builder.AppendLine("    <NoStdLib>false</NoStdLib> ");
            builder.AppendLine("    <NoWarn> ");
            builder.AppendLine("    </NoWarn> ");
            builder.AppendLine("    <Optimize>true</Optimize> ");
            builder.AppendLine("    <RegisterForComInterop>false</RegisterForComInterop> ");
            builder.AppendLine("    <RemoveIntegerChecks>false</RemoveIntegerChecks> ");
            builder.AppendLine("    <TreatWarningsAsErrors>false</TreatWarningsAsErrors> ");
            builder.AppendLine("    <WarningLevel>4</WarningLevel> ");
            builder.AppendLine("    <DebugType>none</DebugType> ");
            builder.AppendLine("    <ErrorReport>prompt</ErrorReport> ");
            builder.AppendLine("    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> ");
            builder.AppendLine("  </PropertyGroup> ");
            builder.AppendLine("  <ItemGroup> ");
            builder.AppendLine("    <Reference Include=\"LCL.Common\"> ");
            builder.AppendLine("      <HintPath>..\\Lib\\LCL.Common.dll</HintPath> ");
            builder.AppendLine("    </Reference> ");
            builder.AppendLine("    <Reference Include=\"System\"> ");
            builder.AppendLine("      <Name>System</Name> ");
            builder.AppendLine("    </Reference> ");
            builder.AppendLine("    <Reference Include=\"System.Data\"> ");
            builder.AppendLine("      <Name>System.Data</Name> ");
            builder.AppendLine("    </Reference> ");
            builder.AppendLine("    <Reference Include=\"System.Drawing\"> ");
            builder.AppendLine("      <Name>System.Drawing</Name> ");
            builder.AppendLine("    </Reference> ");
            builder.AppendLine("    <Reference Include=\"System.Xml\"> ");
            builder.AppendLine("      <Name>System.XML</Name> ");
            builder.AppendLine("    </Reference> ");
            builder.AppendLine("  </ItemGroup> ");
            builder.AppendLine("  <ItemGroup> ");
            var tables = DbObject.GetTables(DbName);
            foreach (var table in tables)
            {
                string className = CodeCommon.GetClassName(table.TableName, TableFormat);
                builder.AppendLine("    <Compile Include=\"" + className + ".cs\" /> ");
            }
            builder.AppendLine("  </ItemGroup> ");
            builder.AppendLine("  <ItemGroup> ");
            builder.AppendLine("    <BootstrapperPackage Include=\"Microsoft.Net.Client.3.5\"> ");
            builder.AppendLine("      <Visible>False</Visible> ");
            builder.AppendLine("      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> ");
            builder.AppendLine("      <Install>false</Install> ");
            builder.AppendLine("    </BootstrapperPackage> ");
            builder.AppendLine("    <BootstrapperPackage Include=\"Microsoft.Net.Framework.3.5.SP1\"> ");
            builder.AppendLine("      <Visible>False</Visible> ");
            builder.AppendLine("      <ProductName>.NET Framework 3.5 SP1</ProductName> ");
            builder.AppendLine("      <Install>true</Install> ");
            builder.AppendLine("    </BootstrapperPackage> ");
            builder.AppendLine("    <BootstrapperPackage Include=\"Microsoft.Windows.Installer.3.1\"> ");
            builder.AppendLine("      <Visible>False</Visible> ");
            builder.AppendLine("      <ProductName>Windows Installer 3.1</ProductName> ");
            builder.AppendLine("      <Install>true</Install> ");
            builder.AppendLine("    </BootstrapperPackage> ");
            builder.AppendLine("  </ItemGroup> ");
            builder.AppendLine("  <ItemGroup> ");
            builder.AppendLine("    <ProjectReference Include=\"..\\IDAL\\" + NameSpace + ".IDAL.csproj\"> ");
            builder.AppendLine("      <Project>{" + IDALGuid + "}</Project> ");
            builder.AppendLine("      <Name>" + NameSpace + ".IDAL</Name> ");
            builder.AppendLine("    </ProjectReference> ");
            builder.AppendLine("    <ProjectReference Include=\"..\\Model\\" + NameSpace + ".Model.csproj\"> ");
            builder.AppendLine("      <Project>{" + ModelGuid + "}</Project> ");
            builder.AppendLine("      <Name>" + NameSpace + ".Model</Name> ");
            builder.AppendLine("    </ProjectReference> ");
            builder.AppendLine("  </ItemGroup> ");
            builder.AppendLine("  <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSharp.targets\" /> ");
            builder.AppendLine("  <PropertyGroup> ");
            builder.AppendLine("    <PreBuildEvent> ");
            builder.AppendLine("    </PreBuildEvent> ");
            builder.AppendLine("    <PostBuildEvent> ");
            builder.AppendLine("    </PostBuildEvent> ");
            builder.AppendLine("  </PropertyGroup> ");
            builder.AppendLine("</Project> ");
            string filename = CodeCommon.DesktopDirectory + NameSpace + @"/DAL/" + NameSpace + ".DAL.csproj";
            CodeCommon.CreateFiles(filename, builder.ToString());
        }
        #endregion
    }
}
